﻿@using myTutor.Models

@{
    ViewBag.Title = "Tin tức";
    ViewBag.ShowMain = true;
    ViewBag.ShowSubFooter = true;
    ViewBag.AdsZoneKey = "HomePage";

    int page = ViewBag.Page ?? 1;
    int nextPage = page + 1;
    int prePage = page - 1;
    int pageSize = Config.GetPageSizeOfNews();
    List<SimpleObject> categories = ArticleCategory.GetSimpleCategories();
}

<h2>Cập nhật tin tức mới nhất</h2>
<div class="function-content-layout function-overview-table">
    <div class="function-content-layout function-overview-table">
    @for (int i = 0; i < categories.Count; i++)
    {
        <input type="hidden" name="categoryId" value="@categories[i].Id" />
        <div class="function-layout-cell">
            <div align="left">
                <label class="function-wrap-title" style="padding-top:14px; padding-bottom:14px;" title="@categories[i].StringValue">@categories[i].StringValue</label>
                @{List<Article> articles = ArticleCategory.GetArtsByPage(categories[i].Id, "3", false, page, pageSize);}
                @if (articles.Count < 1)
                {
                    <p>Thông tin đang được cập nhật thêm...</p>
                }
                else
                {
                    for (int j = 0; j < articles.Count; j++)
                    {
                        <div style="margin-left:5%; margin-right:5%;padding-top:20px;text-align: justify;">
                            <div style="float:left;margin-right:8px;margin-bottom:10px;margin-top:3px;">    
                                @{
                        int index = (page - 1) * pageSize + j + 1;
                        string imagePath = (string.IsNullOrEmpty(articles.ElementAt(j).ImageFileName) ? Config.GetDefaultNewsImage() : articles.ElementAt(j).ImageFileName);
                                }
                                <img src="~/Files/Articles/@imagePath" alt="" width="100px" />
                            </div>    
                            <div style="font-size:14px;font-weight:bold;padding-left:5px">
                                @Html.ActionLink(articles.ElementAt(j).Title, "Detail", "Article", new { id = articles.ElementAt(j).Id, index = index }, null)
                            </div>       
                            <div style="font-size:11px;font-style:italic;padding-left:5px;margin-top:5px">@articles.ElementAt(j).CreatedTime</div>
                            <div style="margin-top:5px;padding-left:5px">
                                @articles.ElementAt(j).PostIntro
                            </div>
                            <div style="clear:both"></div>
                        </div>
                    }
                }
            </div>
        </div>
        if ((i + 1) % 2 == 0)
        {
            <div class="function-content-layout-row"></div>
        }
    }
    </div>
</div>
<div style="padding-top:10px; margin-top:5px; border-top:3px dashed #DADADA; height:50px;" align="center">
Trang: @page/@Article.GetTotalOfPages()
    @if (page > 1)
    {
        <span style="padding-top:8px; float:left;"><strong><a class="button-img but-orange" href="~/Article/Index?page=1"><span class="icon icon-submit"></span><span>Trang đầu</span></a></strong></span>
        <span style="padding-top:8px; float:left;"><strong><a class="button-img but-orange" href="~/Article/Index?page=@prePage"><span class="icon icon-submit"></span><span>Trang trước</span></a></strong></span>

    }
    @if (page < Article.GetTotalOfPages())
    {
        <span style="padding-top:8px; float:right;"><strong><a class="button-img but-blue" href="~/Article/Index?page=@Article.GetTotalOfPages()"><span class="icon icon-submit"></span><span>Trang cuối</span></a></strong></span>
        <span style="padding-top:8px; float:right;"><strong><a class="button-img but-blue" href="~/Article/Index?page=@nextPage"><span class="icon icon-submit"></span><span>Trang sau</span></a></strong></span>
    }
</div>